import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("http://121.43.169.97:8848/pageA.html")

"""
需求：打开注册A.html页面，完成以下操作：
python基础).点击 alert 按钮
2).关闭警告框
3).输入用户名：admin
"""
# python基础
driver.find_element(By.CSS_SELECTOR, "#alerta").click()
# 2
time.sleep(2)
# 获取弹框对象
al = driver.switch_to.alert
# 获取文本信息
print("警告框信息：", al.text)
al.accept()
# 3
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
